package com.galaxy.device.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.galaxy.common.core.domain.R;
import com.galaxy.common.log.annotation.Log;
import com.galaxy.common.log.enums.BusinessType;
import com.galaxy.common.web.core.BaseController;
import com.galaxy.device.domain.bo.DeviceBaseBo;
import com.galaxy.device.domain.bo.DeviceChannelBo;
import com.galaxy.device.domain.vo.DeviceBaseVo;
import com.galaxy.device.domain.vo.DeviceChannelVo;
import com.galaxy.device.service.IDeviceChannelService;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 设备通道管理控制器
 */
@Validated
@RestController
@RequiredArgsConstructor
@RequestMapping("/channel")
public class DeviceChannelController extends BaseController {

    private final IDeviceChannelService deviceChannelService;

    /**
     * 查询设备通道列表
     */
    @GetMapping("/list")
    @SaCheckPermission("device:channel:list")
    public R<List<DeviceChannelVo>> list(DeviceChannelBo bo) {
        return R.ok(deviceChannelService.queryList(bo));
    }

    /**
     * 获取设备通道详细信息
     */
    @GetMapping("/{id}")
    @SaCheckPermission("device:channel:list")
    public R<DeviceChannelVo> getInfo(@PathVariable Long id) {
        return R.ok(deviceChannelService.getInfo(id));
    }

    /**
     * 新增设备通道
     */
    @PostMapping
    @Log(title = "设备通道管理", businessType = BusinessType.INSERT)
    @SaCheckPermission("device:channel:list")
    public R<Void> add(@Validated @RequestBody DeviceChannelBo bo) {
        deviceChannelService.add(bo);
        return R.ok();
    }

    /**
     * 修改设备通道
     */
    @PutMapping
    @Log(title = "设备通道管理", businessType = BusinessType.UPDATE)
    @SaCheckPermission("device:channel:list")
    public R<Void> update(@Validated @RequestBody DeviceChannelBo bo) {
        deviceChannelService.update(bo);
        return R.ok();
    }

    /**
     * 删除设备通道
     */
    @DeleteMapping("/{id}")
    @Log(title = "设备通道管理", businessType = BusinessType.DELETE)
    @SaCheckPermission("device:channel:list")
    public R<Void> delete(@PathVariable Long id) {
        deviceChannelService.delete(id);
        return R.ok();
    }

    /**
     * 批量删除设备通道
     */
    @DeleteMapping("/batch/{ids}")
    @Log(title = "设备通道管理", businessType = BusinessType.DELETE)
    @SaCheckPermission("device:channel:list")
    public R<Void> deleteBatch(@PathVariable Long[] ids) {
        deviceChannelService.deleteBatch(ids);
        return R.ok();
    }

    /**
     * 根据设备ID查询通道列表
     */
    @GetMapping("/device/{deviceId}")
    @SaCheckPermission("device:channel:list")
    public R<List<DeviceChannelVo>> listByDeviceId(@PathVariable Long deviceId) {
        return R.ok(deviceChannelService.queryByDeviceId(deviceId));
    }

}
